<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<c:set var="path" value="${pageContext.request.contextPath }"/>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <script src="https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts.js"></script>
    <%-- <script type="text/javascript"
        src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
     --%>
    <link rel="stylesheet"
          href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script
            src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>
    <script
            src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
    <style type="text/css">
        td {
            border-right: 1px solid;
            height: 50px;
            width: 150px;

        }
        html>body{
            padding: 10px;
            background: #f2f2f2
        }
    </style>
</head>
<body>
<div style="width: 100%; height: 200px;background: #FFFFFF;padding: 10px; border-radius: 5px">
    <span style="font: bold 18px arial, sans-serifi; color:#333; padding-left: 10px;">访问流量</span>
    <table style="text-align: center;width: 70%;">
        <thead>
        <tr>
            <th></th>
            <th style="text-align: center">浏览量（PV）</th>
            <th style="text-align: center">访客数（UV）</th>
            <th style="text-align: center">IP数</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>

<div class="" style="background: #FFFFFF;width: 100%;padding: 5px; border-radius: 5px;margin: 10px 0;">
    <ul class="nav nav-pills">
        <li class="nav-item"><a id="a1" class="nav-link active" href="#" onclick="clickk(this,1,null)">今天</a></li>
        <li class="nav-item"><a class="nav-link" href="#" onclick="clickk(this,2,null)">昨天</a></li>
        <li class="nav-item"><a class="nav-link" href="#" onclick="clickk(this,3,null)">最近7天</a></li>
        <li class="nav-item"><a class="nav-link" href="#" onclick="clickk(this,4,null)">最近30天</a></li>
    </ul>
</div>

<div style="width: 100%; height: 480px;overflow: hidden">

    <div style="border-radius: 5px;padding:10px;width:49%; height:430px;background: #FFFFFF; float: left; margin-right: 1%">
        <div style="width: 100%; height: 50px; background: #FFFFFF; float: left;">
            <ul class="nav nav-pills" style="padding-top: 10px;">
                <li class="nav-item"><a class="nav-link active" href="#" onclick="clickk(this,null,1)">浏览量（PV）</a></li>
                <li class="nav-item"><a class="nav-link" href="#" onclick="clickk(this,null,2)">访客数（UV）</a></li>
            </ul>
        </div>
        <div id="trend" style="border-radius: 5px;width: 100%; height: 350px; background: #FFFFFF; float: left;"></div>
    </div>

    <div id="bar" style="padding:10px;border-radius: 5px; width: 49%; margin-left: 1%; height: 430px; background: #FFFFFF; float: left;"></div>
</div>
<script type="text/javascript"
        src="${path }/resource/js/systools/MBase.js"></script>
<script type="text/javascript">

    var data1 = new Array();
    var data2 = new Array();
    var data3 = new Array();
    var data4 = new Array();
    var myChart = echarts.init(document.getElementById('trend'));
    var myChart1 = echarts.init(document.getElementById('bar'));
    init();

    function init() {
        $.ajax({
            type: "post",
            url: "${path}/do/admin/webVisitorStatistics/getTodayOrLastDayVisitor",
            success: function (result) {
                if (result.status == 200) {
                    var text = " <tr >\n" +
                        "            <td>今日</td>\n" +
                        "            <td>" + result.mapInfo.toDay.pv + "</td>\n" +
                        "            <td>" + result.mapInfo.toDay.uv + "</td>\n" +
                        "            <td>" + result.mapInfo.toDay.ipNum + "</td>\n" +
                        "        </tr>\n" +
                        "        <tr>\n" +
                        "            <td>昨日</td>\n" +
                        "            <td>" + result.mapInfo.lastDay.pv + "</td>\n" +
                        "            <td>" + result.mapInfo.lastDay.pv + "</td>\n" +
                        "            <td>" + result.mapInfo.lastDay.pv + "</td>\n" +
                        "        </tr>"
                    $("tbody").html(text)
                }
            }
        });
        $.ajax({
            type: "post",
            url: "${path}/do/admin/webVisitorStatistics/getVisitor?time=1&type=1",
            success: function (result) {
                if (result.status == 200) {
                    for (var index in result.rows) {
                        data1.push(result.rows[index].date);
                        data2.push(result.rows[index].visitorNum);
                    }
                    //显示标题，图例和空的坐标轴
                    myChart.setOption({
                        title: {
                            text: '趋势图',
                            top: '5%',
                        },
                        grid: {
                            top: '20%',
                        },
                        xAxis: {
                            type: 'category',
                            data: data1
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            data: data2,
                            type: 'line'
                        }]
                    });
                }
            }
        });


        $.ajax({
            type: "post",
            url: "${path}/do/admin/webVisitorStatistics/getAddressVisitor?time=1&type=1",
            success: function (result) {
                if (result.status == 200) {
                    for (var index in result.rows) {
                        data3.push(result.rows[index].address);
                        data4.push(result.rows[index].visitorNum);
                    }
                    // 指定图表的配置项和数据
                    var option = {
                        title: {
                            text: '地域分布'
                        },
                        tooltip: {},
                        legend: {
                            data: ['浏览量']
                        },
                        xAxis: {
                            data: data3
                        },
                        yAxis: {},
                        series: [{
                            name: '浏览量',
                            type: 'bar',
                            data: data4
                        }]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    myChart1.setOption(option);

                }
            }
        });


    }

    var times = 1;
    var types = 1;
    var vi = '浏览量(PV)';

    function clickk(obj, time, type) {

        if (time) {
            times = time;
        }
        if (type) {
            types = type;
            if (type == 1) {
                vi='浏览量(PV)';
            } else {
				vi='访客数(UV)';
            }
        }
        $(obj).addClass("active");
        $(obj).parent().siblings().children().removeClass("active")
        $.ajax({
            type: "post",
            url: "${path}/do/admin/webVisitorStatistics/getVisitor?time=" + times + "&type=" + types,
            success: function (result) {
                if (result.status == 200) {
                    data1 = [];
                    data2 = [];
                    for (var index in result.rows) {
                        data1.push(result.rows[index].date);
                        data2.push(result.rows[index].visitorNum);
                    }
                    //显示标题，图例和空的坐标轴
                    myChart.setOption({
                        title: {
                            text: '趋势图',
                            top: '5%',
                        },
                        grid: {
                            top: '20%',

                        },
                        xAxis: {
                            type: 'category',
                            data: data1
                        },
                        yAxis: {
                            type: 'value'
                        },
                        series: [{
                            data: data2,
                            type: 'line'
                        }]
                    });

                }
            }
        });
        $.ajax({
            type: "post",
            url: "${path}/do/admin/webVisitorStatistics/getAddressVisitor?time=" + times + "&type=" + types,
            success: function (result) {
                if (result.status == 200) {
                    data3 = [];
                    data4 = [];
                    for (var index in result.rows) {
                        data3.push(result.rows[index].address);
                        data4.push(result.rows[index].visitorNum);
                    }
                    // 指定图表的配置项和数据
                    var option = {
                        title: {
                            text: '地域分布'
                        },
                        tooltip: {},
                        legend: {
                            data: [vi]
                        },
                        xAxis: {
                            data: data3
                        },
                        yAxis: {},
                        series: [{
                            name: vi,
                            type: 'bar',
                            data: data4
                        }]
                    };
                    // 使用刚指定的配置项和数据显示图表。
                    myChart1.setOption(option);
                }
            }
        });
    }


</script>
</body>
</html>